package com.ynny.one_dimensional_array01.example;

import java.util.Arrays;
import java.util.Scanner;

public class ArrayScoreTest01 {
    public static void main(String[] args) {
        //1. 根据提示，获取学生人数
        System.out.println("请输入学生的人数:");
        Scanner scanner = new Scanner(System.in);
        int studentCount = scanner.nextInt();

        //2. 根据学生人数，创建指定长度的数组 (使用动态初始化)
        int[] scores = new int[studentCount];

        System.out.println("当前数组长度:"+scores.length);
        System.out.println("请依次输入成绩");
        //3. 使用循环，依次给数组的元素赋值
        int maxScore = 0;
        for (int i = 0; i < scores.length; i++) {
            scores[i] = scanner.nextInt();
            //4. 获取数组中元素的最大值，即为最高分
            if (scores[i] > maxScore){
                maxScore = scores[i];
            }
        }

        System.out.println(Arrays.toString(scores));

        System.out.println("当前成绩最高的为:" + maxScore);

        //5. 遍历数组元素，输出各自的分数，
        // 并根据其分数与最高分的差值，获取各自的等级
        String grade = null;
        for (int i = 0; i < scores.length; i++) {
            if (scores[i] >= maxScore - 10){
                grade = "A";
            } else if (scores[i] >= maxScore - 20) {
                grade = "B";
            } else if (scores[i] >= maxScore - 30) {
                grade = "C";
            } else if (scores[i] >= maxScore - 40) {
                grade = "D";
            }else {
                grade = "E";
            }

            System.out.println("当前学生"+ i +"成绩为" + scores[i] +
                    "等级为" + grade);

        }




    }
}
